package com.gexiaobao.pigeon.ui.adapter

import androidx.core.content.ContextCompat
import com.chad.library.adapter.base.BaseQuickAdapter
import com.gexiaobao.pigeon.R
import com.gexiaobao.pigeon.app.base.DataBindBaseViewHolder
import com.gexiaobao.pigeon.app.model.bean.AppTeamProjectList
import com.gexiaobao.pigeon.databinding.ItemGroupRaceDetailBinding

/**
 * @Author      : hxw
 * @Date        : 2024/7/29 11:06
 * @Describe    :
 */
class AdapterGroupRaceDetail(data: ArrayList<AppTeamProjectList>) :
    BaseQuickAdapter<AppTeamProjectList, DataBindBaseViewHolder>(R.layout.item_group_race_detail, data) {
    override fun convert(holder: DataBindBaseViewHolder, item: AppTeamProjectList) {
        val binding = DataBindBaseViewHolder.getBinding(holder) as ItemGroupRaceDetailBinding
        binding.data = item
        binding.executePendingBindings()//防止列表抖动

        if (holder.layoutPosition % 2 == 0) {//偶数
            holder.setBackgroundColor(R.id.llItem, ContextCompat.getColor(context, R.color.white))
        } else {
            holder.setBackgroundColor(R.id.llItem, ContextCompat.getColor(context, R.color.comm_bg))
        }

        if (item.grade.isNotEmpty()) {
            val sbGrade = StringBuffer()
            item.grade.forEach {
                sbGrade.append(it.trim() + "\n")
            }
            holder.setText(R.id.tvItemGrade, sbGrade.toString().trim())
        } else {
            holder.setText(R.id.tvItemGrade, "--")
        }

        if (item.ringId.isNotEmpty()) {
            val sbRingId = StringBuffer()
            item.ringId.forEach {
                sbRingId.append(it.trim() + "\n")
            }
            holder.setText(R.id.tvItemRingId, sbRingId.toString().trim())
        } else {
            holder.setText(R.id.tvItemRingId, "--")
        }

        if (item.featherColor.isNotEmpty()) {
            val sbFeatherColor = StringBuffer()
            item.featherColor.forEach {
                sbFeatherColor.append(it.trim() + "\n")
            }
            holder.setText(R.id.tvItemFeatherColor, sbFeatherColor.toString().trim())
        } else {
            holder.setText(R.id.tvItemFeatherColor, "--")
        }
    }
}